/** ------------------------------------------------------------------------
 *	VisualGroup JavaScript prototype Classes, version draf
 *  (c) 2006 Bill Vison <vison_ruan@126.com>
 *
 *
/*--------------------------------------------------------------------------*/

/**
 * Prototype Class : "ValueDefined"
 * @prerequire class : 	"Vsg.Common.Logger" 
 */
 

Vsg.Element.ValueDefined = Class.create();
Vsg.Element.ValueDefined.prototype = {
	initialize:function() {
	}
}

/**
 * if the result is true , the result is pass 
 */
Vsg.Element.ValueDefined.defined = function($elementId,$value) {
	
	// set temp value type
	var $tempValue;	// set to be when the type of value is "number" or "string"
	
	// check the value type
	try {
		if ($value == null) {
			throw "value is null";
		}
		
		var $typeofValue = typeof($value);

		if ( $typeofValue == "number" || $typeofValue == "string") {
			$tempValue = $value;
		}
	} catch (ex) {
		$tempValue = "";
	}
		

	
	
	
	// get elemen by id
	var elemObj = document.getElementById($elementId);
	
	if (elemObj.tagName != null) {
		if (elemObj.tagName == "INPUT" ) {
			var elemType = elemObj.type;
			if (elemType == "text" || elemType == "hidden" 
				|| elemType == "button" || elemType == "submit" || elemType == "reset"
				) {
				elemObj.value = $tempValue;
			}
		}

		if (elemObj.tagName == "TEXTAREA" ) {
			elemObj.value = $tempValue;
		}

		if (elemObj.tagName == "SELECT") {
			var elemOptions = elemObj.options;
			// single select vlaue
			if (!elemObj.multiple) {
				var option;
				for (var i = 0 ; i < elemOptions.length ;i++) {
					option = elemOptions[i];
					if (option.value != "") {
						if (option.value == $tempValue) {
							option.selected = true;
							break;
						}

					}
				}
			}

		}
		
		
		
	}
	
}


